package com.module.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;


/**
 * 编辑框对话框
 * showd by dell on 2018/7/5
 */

public class EditableDialog extends BaseBuilder implements View.OnClickListener {
    TextView etContent; //控件
    EditParam mEditParam;

    public EditableDialog(Context context) {
        super(context);
    }

    /**
     * 初始化控件
     */
    @Override
    public void initContentView(){
        mEditParam = new EditParam();
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_editable, null);
        etContent = view.findViewById(R.id.editText);
        setContentView(view);
    }

    @Override
    public BaseBuilder getBuilder() {
        return this;
    }

    @Override
    protected void connectView() {

    }

    public EditableDialog setCallBack(DialogCallBack listener) {
        mEditParam.callBackListener = listener;
        return this;
    }

    /**
     * 重写按钮点击事件
     */
    @Override
    public void onClick(View v) {
        super.onClick(v);
        if(mEditParam.callBackListener != null){
            int tag = Integer.parseInt(v.getTag().toString());
            mEditParam.callBackListener.callback(tag, etContent.getText().toString());
        }
    }

    public class EditParam {
        public DialogCallBack callBackListener;

    }

    public interface DialogCallBack{
        void callback(int which, String result);
    }
}